﻿<?php
	@session_start();
	include('lib_db.php');
	/*****************code phần cart****************/

	if(isset($_GET['themgiohang'])){
		$id= $_GET['themgiohang'];
		if(isset($_SESSION['giohang'] ) && is_array($_SESSION['giohang'])){
			$count = count($_SESSION['giohang']);//đếm số phần tử trong giỏ hàng
			//echo $count;
			$flag=false;// khởi tạo biến flag nếu nó đã trùng
			for($i=0; $i< $count; $i++ ){
				if($_SESSION['giohang'][$i]["idBook"]==$id){
					$_SESSION['giohang'][$i]["soluong"] += 1;
					$flag=true;// thì flag =treu và thoát khỏi vòng lặp
					break;
				}
			}
			if($flag==false){//nếu không tồn tại giỏ hàng thì ta thêm sp đó vào cuối giỏ hàng.
				$_SESSION['giohang'][$count]["idBook"]= $id;
				$_SESSION['giohang'][$count]["soluong"]=1;
			}
			
		}
		else{
			$_SESSION['giohang']= array();
			$_SESSION['giohang'][0]["idBook"]= $id;
			$_SESSION['giohang'][0]["soluong"]=1;
		}
		//echo $_SESSION['giohang'][0]["soluong"];
		header("location: index.php");
	}
	//echo $_SESSION['giohang'][0]["soluong"];
	
	

	$sql = "select * from category_book ";
	$menu_left = select_list($sql);
	
	$sql = "select * from book ";
	$sql.="order by idBook DESC limit 6";
	$newbook = select_list($sql);
	
	$sql = "select * from book ";
	$sql.="where SaleOff >=20 limit 2";
	$Sach_DB = select_list($sql);
	
	

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title> BÁN SÁCH TRỰC TUYẾN </title>
		<link type="text/css" rel="stylesheet" href="css/style.css" />
		<link href="css/js-image-slider.css" rel="stylesheet" type="text/css"/>
		<script src="js/js-image-slider.js" type="text/javascript"></script>
		<script src="js/stickytooltip.js" type="text/javascript"></script>
		<link href="css/generic.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<div id ="wrapper">
			<div id ="header"><?php include("header.php");?></div><!--end header-->		
			<div id ="content">
				<div class="content-header"><?php include ("header-content.php")?></div> <!--end content-header-->
				
						<div class="clear-both"></div>			
				<div class="content-menu">
					<div class ="content-menu-left "><?php include ("content-menu-left.php")?></div>	<!--end content-menu-left -->					
					<div class="content-menu-center">
						<div class="content-menu-center-header">
												
									<div id="sliderFrame">
									<div id="slider">
										<a href="http://www.menucool.com/javascript-image-slider" target="_blank">
											<img src="img/1.png" alt="Điệp Bắp 1992" />
										</a>
										<img src="img/2.png"alt="" />
										<img src="img/3.png" alt="" />
										<img src="img/4.png" alt="" />
										<img src="img/5.png" />
									</div>
									<div id="htmlcaption" style="display: none;">
										<em>HTML</em> caption. Link to <a href="http://www.google.com/">Google</a>.
									</div>
								</div>							
						</div> <!--end content-menu-center-header-->			
							<div class="content-menu-center-footer">
							<div class= "sach-moi">
								<P>SÁCH MỚI </P>
							</div>
							<div class= "san-pham">
								<div class= "san-pham1">
								
								
								<?php if($newbook) foreach ($newbook as $sanpham){?>
								
									<div class="wru-box">									
										<div class="wru-box-header">
											<div class="tieu-de"><a  href="<?php echo $sanpham ["Link"]?>?id=<?php echo $sanpham ["idBook"]?>" title="<?php echo $sanpham ["Name"]?>" style="padding-left:10px;"> <?php echo $sanpham ["Name"]?></a></div> 
										</div>
										<div class="wru-box1">
											<div class="wru-box11">	
												<a href="#"><img src="img1/<?php echo $sanpham ["ImgCover"]?>"></a>
											</div>
											<div class="wru-box12">
												<ul>
													
													Tắc giả: <a class="color1" title="More about Joe Vitale" href="#"><?php echo $sanpham ["Author"]?></a> <br/>	
												
													Dịch giả: <font color="#00775b" style="font-weight:bold"><?php echo $sanpham ["Translator"]?></font><br/>
													Giá bán: <span class="gia-ban"><?php if($sanpham ["SalePrice"]>0) {echo number_format($sanpham ["SalePrice"], 0, ',', ' '); }?>d </span>  
												</ul>							
											</div>
										</div>			
										<div class="wru-box2"style="padding-right:9px;">
										 
											<a class="viewsp" title="View" href="#"></a>
											<a class="shopcart" title="Add to cart" href="index.php?themgiohang=<?php echo $sanpham ["idBook"]?>"></a>										
										</div>
									</div>	
								<?php } ?>	
									
															
							</div><!-- end san pham1-->
                          
						</div> <!-- end san pham-->
						<div class="sach-dac-biet">
                            SÁCH GIẢM GIÁ ĐẶC BIỆT
                        </div>
						<?php if($Sach_DB) foreach ($Sach_DB as $sanpham_gg){?>
										
						<div class="sach-dac-biet1">
							<div class="sach-đac-biet11">
								<div class="tieu-de"><a title="<?php echo $sanpham_gg ["Name"]?>" href="<?php echo $sanpham_gg ["Link"]?>?id=<?php echo $sanpham_gg ["idBook"]?>"><?php echo $sanpham_gg ["Name"]?></a></div>
							</div>
							<div class="sach-dac-biet12">
								<div class="sach-dac-biet121">
									<div class="sach-dac-biet1211">
										<img src="img1/<?php echo $sanpham_gg ["ImgCover"]?>" width=100, height=100>
										<!-- sảm phẩm giảm giá -->
									</div>
									<div class="sach-dac-biet1212">
										
										<P style="font-size:13px;"><?php echo $sanpham_gg ["Description"]?><br/></P>
										Tắc giả:<a class="color1" title="Luis Sepúlveda" href="#"> <?php echo $sanpham_gg ["Author"]?></a> <br/>

										Dịch giả:<font color="#00775b" style="font-weight:bold"> <?php echo $sanpham_gg ["Translator"]?></font></BR>
									</div>
					
								</div>
								<div class="sach-dac-biet122">
									<div class="sach-dac-biet1221">
										
											<img src="img1/bg_price.gif">
										
										<div class="sach-dac-biet12212-trang-chu">
											Giá bán: <span class="gia-ban"><?php   if($sanpham_gg ["SalePrice"]>0){ echo number_format($sanpham_gg ["SalePrice"]*1, 0, ',', ' '); } ?></span><br/>
										
											Giá bìa: <font style="text-decoration: line-through;color:red;font-size:15px"><?php if($sanpham_gg ["SalePrice"]>0){echo number_format($sanpham_gg ["SalePrice"], 0, ',', ' ');}?></font>
										</div>
										<div class="giam-gia">
											<p>Giảm <br/><?php echo $sanpham_gg ["SaleOff"]?>%</p>
										</div>
									</div>
									<div class="sach-dac-biet1222"style="padding-right:9px;">
										 
										<a class="viewsp" title="View" href="#"></a>
										<a class="shopcart" title="Add to cart" href="index.php?themgiohang=<?php echo $sanpham_gg ["idBook"]?>"></a>
									</div>
								</div>
							</div>
						</div>
					<?php } ?>	
						
						
						
																	
					</div> <!--end content-menu-center-footer-->
				</div> <!--end content-menu-center-->
					<div class ="content-menu-right"><?php include ("content-menu-right.php")?></div> <!--end content-menu-right-->
								
				</div> <!--end content-menu-->
			
			</div> <!--end content-->
			<div id ="footer"><?php include("footer.php");?></div><!--end footer-->
			
		
		</div><!--end wapper-->
	</body>
</html>
